package demo1;

import java.util.PriorityQueue;
import java.util.Stack;

public class Test1 {
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        Stack<Character> stack  = new Stack<>();

    }
}
class Solution2 {
    public boolean isValid(String s) {
        if(s == null) return false ;
        Stack<Character> stack  = new Stack<>() ;
        for(int i = 0 ; i < s.length() ; i ++){
            char tmp = s.charAt(i);
            if(stack.empty()){
                stack.push(tmp);
            }else{
                if(tmp==')' || tmp==']' || tmp =='}'){
                    char top = stack.peek() ;
                    switch(top){
                        case '(': if(tmp != ')') return false ;
                            break ;
                        case '[':  if(tmp != ']') return false ;
                            break ;
                        case '{': if(tmp != '}') return false ;
                            break ;
                        default : return false ;
                    }
                    stack.pop() ;
                }else{
                    stack.push(tmp);
                }
            }
        }
        if(stack.empty()){
            return true ;
        }
        return false ;
    }
}